package org.spiderflow.core.executor.function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spiderflow.common.annotation.Comment;
import org.spiderflow.common.annotation.Example;
import org.spiderflow.common.executor.FunctionExecutor;
import org.springframework.stereotype.Component;

/**
 * Created on 2019-12-06
 *
 * @author Octopus
 */
@Component
@Comment("thread常用方法")
public class ThreadFunctionExecutor implements FunctionExecutor {
    private static final Logger LOGGER = LoggerFactory.getLogger(ThreadFunctionExecutor.class);

    @Override
    public String getFunctionPrefix() {
        return "thread";
    }

    @Comment("线程休眠")
    @Example("${thread.sleep(1000L)}")
    public static void sleep(Long sleepTime) {
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            LOGGER.warn("线程休眠失败", e);
        }
    }
}
